#ifndef __HAL_FLOW_H
#define __HAL_FLOW_H

#include "main.h"

#define LOST_WATER_TIME 120

typedef enum
{   
	  FLOW_PURE,				//纯水流量计
	  FLOW_NOR1,				//常温水1流量计
	  FLOW_NOR2,				//常温水2流量计
	  FLOW_HEAT1,   		//热水1流量计
	  FLOW_HEAT2,				//热水2流量计
	  FLOW_MAX_NUM,
}teFLOWIndex;


typedef struct
{
	uint64_t tickStart;//流量开始计时
	uint64_t tickEnd;//流量结束计时
	uint32_t tickCnt;//流量脉冲累计个数
	uint32_t flow_ml;//累计净水 mL
	uint32_t flowPer;//净水流量 mL/min
	uint32_t ctrlFlowPer;//用于通知控制板的平均流量值
	//以下用于自吸D1流量计告警
	uint32_t error;//流量故障标记
	uint16_t errorFlowBuff[LOST_WATER_TIME];//2分钟内平均流量
	uint16_t errorFlowBuffIndex;//buffIndex
	uint32_t errorFlowCnt;//每s的平均计数值
	uint8_t  lackOfWaterCnt;//缺水计数
	uint32_t timeCnt;//时间累计
	uint32_t saveTickCnt;
}tsTypeFlowInfo;

extern tsTypeFlowInfo gFlowInfo[FLOW_MAX_NUM];
extern void OnInitFlow(teFLOWIndex i);
//uint8_t OnCheckFlowValue(uint32_t makingcnt);
//uint8_t OnCheckFlowPerSecend(void);
//uint32_t OnGetFlowValue(uint32_t totalcnt, uint32_t second);
uint8_t OnCheckFlowValue(uint32_t makingcnt,teFLOWIndex flowPort );  //获得流速 和流量
uint8_t OnCheckFlowPerSecend(teFLOWIndex flowPort);
uint32_t OnGetFlowValue(uint32_t totalcnt, uint32_t second,teFLOWIndex flowPort );  //返回流速
extern void OnHalFlowTest(void);
#endif

